'/
' RabNet (Rabid Networking)
' 
' This is a strimmed down BlitzMax port of RakNet. It is basically inspired
' by RakNet, but is very strimmed down, and a bunch of new additional
' features has been added, all written from scratch.
' 
' Copyright (c) 2003 Jenkins Software LLC.
' RabNet written 2010 by Anton Berlin.
' 
' =========================================================================
' 
' All new features is free to use in any way, as long as you inlude
' Anton Berlin (or Anthony Berlin) as the orinial writer of the code.
' 
' All old features are subject to the appropriate license agreement.
' Creative Commons Licensees are subject to the license found at
' http://creativecommons.org/licenses/by-nc/2.5/
' 
' Single application licensees are subject to the license found at
' http://www.jenkinssoftware.com/SingleApplicationLicense.html
' 
' Custom license users are subject to the terms therein.
' 
' GPL license users are subject to the GNU General Public
' License as published by the Free Software Foundation; either version 3
' of the License, or (at your option) any later version.
'/

'// This represents a user message to or from another system.
type Packet

	'// -------------------------------------------------------------------------------------------------------------
	'// Convert the data to a regular string and return it.
	'// -------------------------------------------------------------------------------------------------------------
	method toString:string()
	
		return string.fromCString(m_data);
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Return the data, as a C-string.
	'// -------------------------------------------------------------------------------------------------------------
	method getData:byte ptr()
	
		return m_data;
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Return the packet identifier, which is the first byte of the data.
	'// -------------------------------------------------------------------------------------------------------------
	method getPacketIdentifier:byte()
	
		return m_data[0];
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Return the all but the first byte of the data, which is the message.
	'// -------------------------------------------------------------------------------------------------------------
	method getMessage:string()
	
		return string.fromCString(m_data)[1..];
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Return the system address of the sender of this packet.
	'// -------------------------------------------------------------------------------------------------------------
	method getSystemAddress:SystemAddress()
	
		return m_sender;
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Return the guid of the sender of this packet.
	'// -------------------------------------------------------------------------------------------------------------
	method getGuid:long()
	
		return m_guid;
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Return the length of the message.
	'// -------------------------------------------------------------------------------------------------------------
	method getMessageLength:int()
	
		return m_length - 1; '// We subtract by one because we don't count the first byte, the id byte.
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Return the size of the data this packet contains.
	'// -------------------------------------------------------------------------------------------------------------
	method getSize:int()
	
		return m_length;
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// The system that sent this packet.
	'// -------------------------------------------------------------------------------------------------------------
	field m_sender:SystemAddress;
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Only used when sending the packet. Represents the recipient of the packet, or who not to send the packet to,
	'// if we're broadcasting.
	'// -------------------------------------------------------------------------------------------------------------
	field m_recipient:SystemAddress;
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Whether or not to broadcast this packet.
	'// -------------------------------------------------------------------------------------------------------------
	field m_broadcast:byte = false;
	
	'// -------------------------------------------------------------------------------------------------------------
	'// A unique identifier for the system that sent this packet, regardless of IP address. Only valid once a
	'// connection has been established (ID_CONNECTION_REQUEST_ACCEPTED, or ID_NEW_INCOMING_CONNECTION). Until that
	'// time it will be UNASSIGNED_RABNET_GUID.
	'// -------------------------------------------------------------------------------------------------------------
	field m_guid:long;
	
	'// -------------------------------------------------------------------------------------------------------------
	'// The length of the data in bytes
	'// -------------------------------------------------------------------------------------------------------------
	field m_length:int;
	
	'// -------------------------------------------------------------------------------------------------------------
	'// The data from the sender
	'// -------------------------------------------------------------------------------------------------------------
	field m_data:byte ptr;

end type
